﻿Imports System.Collections.Specialized

Public Class MoneyOut

    Private Sub btnOk_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOk.Click

        Dim date3 As Date = New Date(dt月别开始时间.Value.Year, dt月别开始时间.Value.Month, dt月别开始时间.Value.Day)
        Dim date4 As Date = New Date(dt月别结束时间.Value.Year, dt月别结束时间.Value.Month, dt月别结束时间.Value.Day)
        If date3 > date4 Then
            ShowMessageBox("开始时间不能大于结束时间")
            dt月别开始时间.Focus()
            Exit Sub
        End If

        Dim cv As New CrystlViewer
        If rad收入.Checked Then
            cv._ParamsValues.Add("TITLE", "收入一览表")
            cv._Rt = CrystlViewer.ReportType.InMonth
        Else
            cv._ParamsValues.Add("TITLE", "支出一览表")
            If rad流水账.Checked Then
                cv._Rt = CrystlViewer.ReportType.OutMonth
            Else
                cv._Rt = CrystlViewer.ReportType.OutMonth1
            End If
        End If

        If rad分类.Checked Then
            If chk按用户.Checked Then
                cv._ParamsValues.Add("分类1", True)
            Else
                cv._ParamsValues.Add("分类1", False)
            End If

            cv._ParamsValues.Add("分类2", False)

            If Me.chk按支出收入.Checked Then
                cv._ParamsValues.Add("分类3", True)
            Else
                cv._ParamsValues.Add("分类3", False)
            End If
        End If
        Dim date1 As New Date(Me.dt月别开始时间.Value.Year, Me.dt月别开始时间.Value.Month, 1)
        Dim date2 As New Date(Me.dt月别结束时间.Value.Year, Me.dt月别结束时间.Value.Month, Date.DaysInMonth(Me.dt月别结束时间.Value.Year, Me.dt月别结束时间.Value.Month))
        cv._ParamsValues.Add("开始时间", date1.ToString)
        cv._ParamsValues.Add("结束时间", date2.ToString)

        If Me.txtUsername.Text.Trim <> "" AndAlso Me.CheckBox1.Checked Then
            cv._ParamsValues.Add("用户", CStr(Me.txtUsername.Tag))
        End If

        Using cv
            cv.ShowDialog()
        End Using
    End Sub

    Private Sub btnCancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCancel.Click
        Me.Close()
    End Sub

#Region "窗体数据保存的重载方法 A-2010-09-06"
    Public Overrides Sub 保存窗体数据到数据库(ByRef dtData As System.Data.DataTable)

        If rad流水账.Checked Then
            dtData.Rows.Add(New Object() {"类型", "", "流水账"})
        Else
            dtData.Rows.Add(New Object() {"类型", "", "分类别"})
        End If

        If rad收入.Checked Then
            dtData.Rows.Add(New Object() {"收入支出", "", "收入"})
        Else
            dtData.Rows.Add(New Object() {"收入支出", "", "支出"})
        End If

        dtData.Rows.Add(New Object() {"开始时间.年", "", dt月别开始时间.Value.Year.ToString})
        dtData.Rows.Add(New Object() {"开始时间.月", "", dt月别开始时间.Value.Month.ToString})

        dtData.Rows.Add(New Object() {"结束时间.年", "", dt月别结束时间.Value.Year.ToString})
        dtData.Rows.Add(New Object() {"结束时间.月", "", dt月别结束时间.Value.Month.ToString})

        If chk按用户.Checked Then
            dtData.Rows.Add(New Object() {"分类1", "", "按用户"})
        End If

        If chk按支出收入.Checked Then
            dtData.Rows.Add(New Object() {"分类3", "", "按支出收入"})
        End If
    End Sub

    Public Overrides Sub 存取数据库数据到窗体(ByVal dtDbData As System.Data.DataTable)
        If dtDbData.Rows.Count > 0 Then

            If 查找数据("类型", "", "流水账", dtDbData) = "流水账" Then
                rad流水账.Checked = True
            Else
                rad分类.Checked = True
            End If

            If 查找数据("收入支出", "", "收入", dtDbData) = "收入" Then
                rad收入.Checked = True
            Else
                rad支出.Checked = True
            End If

            If 查找数据("分类1", "", "", dtDbData) = "按用户" Then
                chk按用户.Checked = True
            End If

            If 查找数据("分类3", "", "", dtDbData) = "按支出收入" Then
                chk按支出收入.Checked = True
            End If
        End If

        Dim date1 As New Date(CInt(查找数据("开始时间.年", "", Me.dt月别开始时间.Value.Year.ToString, dtDbData)), CInt(查找数据("开始时间.月", "", "1", dtDbData)), 1)
        Me.dt月别开始时间.Value = date1
        date1 = New Date(CInt(查找数据("结束时间.年", "", Me.dt月别开始时间.Value.Year.ToString, dtDbData)), CInt(查找数据("结束时间.月", "", "1", dtDbData)), 1)
        Me.dt月别结束时间.Value = date1
    End Sub

#End Region

    Private Sub btnUsername_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnUsername.Click
        Using frm As Wys.Control.Vb.ListForm = New Wys.Control.Vb.ListForm
            frm.strName = Me.strName
            frm.iType = Me.iType
            frm.SQL = "select ID,UserName as 名称 from WysInputUser"
            Dim 显示列 As New StringCollection
            显示列.Add("名称")
            frm.Width = 100
            frm.Height = 200
            frm.显示列 = 显示列
            frm.ShowDialog()
            If frm.返回值.Count > 0 Then
                txtUsername.Tag = CStr(frm.返回值(0))
                txtUsername.Text = CStr(frm.返回值(1))
            End If
        End Using
    End Sub

    Private Sub MoneyOut_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Me.txtUsername.Tag = ""
    End Sub

    Private Sub CheckBox1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox1.CheckedChanged
        If Me.CheckBox1.Checked Then
            Me.txtUsername.Enabled = True
            Me.btnUsername.Enabled = True
        Else
            txtUsername.Text = ""
            Me.txtUsername.Enabled = False
            Me.btnUsername.Enabled = False
        End If
    End Sub

    Private Sub rad收入_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles rad收入.Click, rad支出.Click
        If Me.rad收入.Checked Then
            GroupBox5.Enabled = False
            GroupBox6.Enabled = False
            rad流水账.Checked = True
        Else
            GroupBox5.Enabled = True
            GroupBox6.Enabled = False
        End If
    End Sub

    Private Sub rad流水账_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles rad流水账.Click, rad分类.Click
        If rad流水账.Checked Then
            GroupBox6.Enabled = False
        Else
            GroupBox6.Enabled = True
        End If
    End Sub
End Class
